<?php

namespace App\Http\Controllers\Merchant;

use App\Deploy;
use App\Http\Response;
use App\Mail\Code;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Mail;

class DeployController extends Controller
{
    use Response;
    public function index(Request $request)
    {
        $result=Deploy::paginate($request->get('pageSize'),'*','pageNo');;

        return $this->success(200,$result);
    }
    public function store(Request $request)
    {
        $code=uniqid();
        $password=uniqid();
        if (Deploy::where('email',$request->get('email'))->first()){
            return $this->error(505,trans('topic.email has been created'));
        }
        $data=[
            'email'=>$request->get('email'),
            'code'=>$code,
            'password'=>$password
        ];
        $create=Deploy::create($data);
        if ($create){
            Mail::to($request->get('email'))->send(new Code($code,$password));
            return $this->message(200,trans('topic.create success'));
        }else{
            return $this->error(505,trans('topic.create_failed'));
        }
    }
}
